import 'package:flutter/material.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBNavigator.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBImageStyle/YBImageStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';

class YBScannInfoPage extends StatefulWidget {
  @override
  _YBScannInfoPageState createState() => _YBScannInfoPageState();
}

class _YBScannInfoPageState extends State<YBScannInfoPage> {

  QRViewController controller;
  final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');

  @override
  Widget build(BuildContext context) {
    return Container(
       child: Scaffold(
         // appBar: AppBar(
         //   elevation: 0,
         //   leading: InkWell(
         //     child: Padding(
         //        padding: EdgeInsets.only(left:YBTextStyle.adapterSize10),
         //        child: Image.asset(YBImageStyle.getImagePath('common_whiteImage')),
         //     ),
         //     onTap: (){
         //       YBNavigatorUtil.goDefaultBack(context);
         //     },
         //   ),
         //   backgroundColor: Colors.black,
         // ),
         body: Stack(
           children: [
             Expanded(
               child:QRView(
                  key: qrKey,
                  onQRViewCreated: _onQRViewCreated,
                  overlay: QrScannerOverlayShape(
                    borderRadius: 1,
                    borderColor: YBColor.commonThemeColor,
                    borderLength: YBTextStyle.adapterSize40,
                    borderWidth: 1,
                    cutOutSize: YBTextStyle.adapterSize350,
                  ),
               ),
             ),
             Container(
               alignment: Alignment.centerLeft,
               height: YBTextStyle.adapterSize110,
               child: InkWell(
                 child: Padding(
                   padding: EdgeInsets.only(left:YBTextStyle.adapterSize20),
                   child: Image.asset(YBImageStyle.getImagePath('common_whiteImage')),
                 ),
                 onTap: (){
                   YBNavigatorUtil.goDefaultBack(context);
                 },
               ),
             ),
           ],
         ),
       ),
    );
  }

  void _onQRViewCreated(QRViewController controller){
    this.controller = controller;
    controller.scannedDataStream.listen((event) {
       setState(() {

       });
    });
  }

  @override
  void dispose() {
    // TODO: implement dispose
    controller.dispose();
    super.dispose();
  }

}
